package com.example.depcontrol.service.imp;

import com.example.depcontrol.mapper.DeptMapper;
import com.example.depcontrol.mapper.EmpMapper;
import com.example.depcontrol.pojo.Dept;
import com.example.depcontrol.service.DeptService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServicelmp implements DeptService {
    @Resource
    private DeptMapper deptMapper;

    @Resource
    private EmpMapper empMapper;

    @Override
    public List<Dept> list(){
        return deptMapper.list();
    }

    @Transactional
    @Override
    public void delete(Integer id) {
        deptMapper.deleteById(id);
        empMapper.deleteByDeptId(id);
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    @Override
    public Dept checkById(Integer id) {
        return deptMapper.selectById(id);
    }

    @Override
    public void alterDep(Dept dept) {
        deptMapper.alterDep(dept);
    }


}
